package se.jocke.nb.proxy.monitor.model;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jocke
 */
public class HttpMessage {

    private String path;

    private String method;

    private int statusCode;

    private String reasonPhrase;

    private final String transactionId;

    private Map<String, List<String>> requestParameters;

    private Map<String, String> requestHeaders;

    private Map<String, String> responseHeaders;
    
    private byte[] content;

    private byte[] body;

    private MessageState state = MessageState.REQUEST;

    public HttpMessage(String transactionId) {
        this.transactionId = transactionId;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public Map<String, List<String>> getRequestParameters() {
        return requestParameters == null ? Collections.EMPTY_MAP : requestParameters;
    }

    public void setRequestParameters(Map<String, List<String>> requestParameters) {
        this.requestParameters = requestParameters;
    }

    public Map<String, String> getRequestHeaders() {
        return requestHeaders == null ? Collections.EMPTY_MAP : requestHeaders;
    }

    public void setRequestHeaders(Map<String, String> requestHeaders) {
        this.requestHeaders = requestHeaders;
    }

    public Map<String, String> getResponseHeaders() {
        return responseHeaders == null ? Collections.EMPTY_MAP : responseHeaders;
    }

    public void setResponseHeaders(Map<String, String> responseHeaders) {
        this.responseHeaders = responseHeaders;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public MessageState getState() {
        return state;
    }

    public void setState(MessageState state) {
        this.state = state;
    }

    public String getReasonPhrase() {
        return reasonPhrase;
    }

    public void setReasonPhrase(String reasonPhrase) {
        this.reasonPhrase = reasonPhrase;
    }

    public byte[] getContent() {
        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.transactionId != null ? this.transactionId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final HttpMessage other = (HttpMessage) obj;
        return !((this.transactionId == null) ? (other.transactionId != null) : !this.transactionId.equals(other.transactionId));
    }

    @Override
    public String toString() {
        return "HttpMessage{" +"message=" + transactionId + "path=" + path + ", method=" + method + ", statusCode=" + statusCode + '}';
    }

}